package com.sky.module.system.OperLog.config;

import com.sky.module.support.log.listener.SysLogListener;
import com.sky.module.system.OperLog.service.OperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author
 * @date 2023/3/8 8:24
 **/
@Configuration
public class OperLogConfig {


    @Autowired
    private OperLogService operLogService;
    private ExecutorService threadPool = Executors.newFixedThreadPool(1);

    @Bean
    public SysLogListener sysLogListener() {

//        TODO 这里相当于自定义日志处理的逻辑
//        TODO 使用多线程的方式
        return new SysLogListener(sysOperLog -> {
            threadPool.execute(() -> {
                operLogService.save(sysOperLog);
            });
        });
    }
}
